<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/ztree/jquery.ztree.core-3.5.js" type="text/javascript"></script>
<script type="text/javascript">
$("#deliver").select2();
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        callback:{
            onClick: zTreeOnClick
        }
    };

    var zNodes =[
    <?php foreach($departs as  $item):?>
    {id:<?php echo $item['id'];?>, pId:<?php echo $item['pid'];?>, name:"<?php echo $item['name'];?>",<?php echo $item['id']==1 ? "open: true" : '' ;?>},
    <?php endforeach;?>
    ];

    function zTreeOnClick( event, treeId, treeNode){
      var depart_id = treeNode.id;
        $.get("/Sign/get_delivery", {"depart_id": depart_id}, function (data) {
            var optstr = '';
            if (data.code == 200) {
                console.log(data.data);
                $.each(data.data, function (k, val) {
                    optstr += "<option value='" + val.emp_id + "'>" + val.real_name + "</option>"
                })
            }
            $("#deliver").html(optstr);
        }, "json");
        $("#depart_id").val(treeNode.id);
        $("#onadd").val(treeNode.name);
        $(".select-box .zTreeDemoBackground").fadeOut();
    }
    $(document).ready(function(){
        $.fn.zTree.init($("#tree"), setting, zNodes);

        $(".select-box .menList").click(function(){
            $(".select-box .zTreeDemoBackground").fadeToggle();
            $("#tree").show();
        })

        $(".select-box .menList").click(function(event){
                $(this).siblings("ul").fadeIn()
                $(this).parent().siblings("li").find("ul").fadeOut();
                event.stopPropagation();
        });
    
        $("body").click(function(event){
            $(".select-box .menbox").fadeOut();
            $(".select-box .zTreeDemoBackground").fadeOut();
            event.stopPropagation();
        })
        $(".zTreeDemoBackground").click(function(event){       
             event.stopPropagation();
        })
    });
  
    function popup(opp){
         $(opp).parent().siblings("input").val($(opp).html());
         $(opp).parent().fadeOut();
    }
</script>

<style>
.select-box{
    float:left; position: relative;
}
.select-box .menList{background: #fff url(http://img3.isou365.cn/paimai/yunying/images/sanjiao.jpg) no-repeat 200px 7px;
    display: block;
    cursor: pointer;
    text-align: center;
    width: 200px;
    border:solid 1px #d2d2d2;
    height:24px; line-height: 24px;
    float: left;
    }
    .select-box .zTreeDemoBackground{ display: none; position: absolute;left:0;top:26px; background:#fff;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
<include file="Public/sidebar"  menu="shgl.qydd" />
    <div class="mianR">
        <h3 class="yonghu">签约分配</h3>
        <div class="chezhu-xinxi">
          <div class="xinxi-conter">
            <h4>拍卖单号：{$order.order_no}</h4>
            <ul>
              <li class="clearfix">
                <em>预约时间</em><em class="name-text1">{$owner.sign_reserve_time} </em>
                <em>车型</em><em class="dian-hua1">{$owner.car_model}</em>
              </li>
              
              <li class="clearfix">
                  <?php if($owner['sign_service_method']==3):?>
                      <em>预约门店</em><em class="name-text1">{$terminal}</em>
                  <?php else:?>
                    <em>预约地址</em><em class="name-text1">{$owner.address}</em>
                  <?php endif;?>
              </li>
              <li class="clearfix">
              <?php if($remark['result']== 1):?>
                <em>确定备注</em>
              <?php elseif ($remark['result']== 4):?>
                <em>磋商备注</em>
              <?php endif;?>
               
                <em class="name-text1">{$remark.remark} </em>
              </li>
              <li class="clearfix">
                <em>所在地</em><em class="name-text1">{$location_area}</em>
              </li>
            </ul>
          </div>
          <div class="distribution">
           <form id="signForm" action="" >
                <dl class="clearfix">
                  <dt>分配到</dt>
                  <!-- <dd class="shengshi"><input type="text" value="请选择地区"></dd> -->
                 <div class="select-box">
                      <input type="text" id="onadd" class="menList" readonly="请选择所属部门" value="请选择所属部门">
                      <div class="zTreeDemoBackground left">
                            <ul id="tree" class="ztree"></ul>
                        </div>
                  </div>
                  <input type='hidden' id='depart_id' name="depart_id" value="" />
                  <div class="select-box">
                    <select name="deliver_id" id="deliver" style="width:162px;margin-left: 20px;">
                        <option>请选择交付顾问</option>
                    </select>
                  </div>
                </dl>
                <dl class="clearfix">
                  <dt>备注</dt>
                  <dd>
                      <textarea name="sign_reserve_remark"></textarea>
                  </dd>
                </dl>
                <input name="owner_id" type="hidden" value="{$owner.owner_id}">
                <input name="order_id" type="hidden" value="{$order.order_id}">
            </form>
          </div>
        </div>
        <div class="yongBtn">
          <input id="sign_submit" type="submit" value="确定" class="queding">
          <input type="button" onclick="history.back();" class="quxiao" value="取消">
        </div>
    </div>
    </body>
</html>
<script type="text/javascript">
$("#store,#deliver").select2();

$("#store").change(function(){
    var store_id = $(this).val();
    $.get("/Sign/getDeliver",{"store_id":store_id},function(data){
        var    optstr = '';
        if(data.code==200){
               $.each(data.data,function(k,val){
                optstr += "<option value='" + val.emp_id + "'>"+ val.real_name +"</option>"
               })
        }
        $("#deliver").html(optstr);
    },"json");
});

$("#sign_submit").click(function(){
    $.post("/Sign/saveDisPatch",$("#signForm").serialize(),function(data){
        if(data.code!=200){
            shibai_alert(data.msg);    
            return false;
        }
        btn_alert("分配成功");
        setTimeout("location.href=document.referrer",1000);
    },"json");
});
</script>